package server;

import java.util.HashMap;

/**
 * 
 * @author Peewhy
 */
public class ContentType {
    private HashMap hm;
        
    /**
     * Adds basic types like html, css, xml...
     */
    private void addBasicTypes() {
        addType(".html", "text/html");
        addType(".doc", "application/msword");
        addType(".gif", "image/gif");
        addType(".jpg", "image/jpeg");
        addType(".pdf", "application/pdf");
        addType(".css", "text/css");
        addType(".xml", "text/xml");
        addType(".jar", "application/x-java-archive");
    }
    
    /**
     * Returns content type strings for respond header
     * @param File extension
     * @return Content type string for particular extension
     */
    public String getContentType(String s) {
        return (String) hm.get(s);
    }
    
    /**
     * Associates filetype extension with content type
     * @param extension Suffix of file, like txt
     * @param s File type associated with extension
     */
    public void addType(String extension, String s) {
        hm.put(extension, s);
    }
    
    /**
     * Adds basic types
     */
    public ContentType() {
        hm = new HashMap();
        addBasicTypes();
    }
    
}
